﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dycox.Workflows
{
    internal class TransitionOperationComparer : IEqualityComparer<TransitionOperation>
    {
        private static TransitionOperationComparer _instance;

        public static TransitionOperationComparer Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new TransitionOperationComparer();
                return _instance;
            }
        }


        public bool Equals(TransitionOperation x, TransitionOperation y)
        {
            if (x == null && y == null)
                return true;

            if (x == null || y == null)
                return false;

            if (x.GetType() == y.GetType())
                return x.Token == y.Token;

            return false;
            
        }

        public int GetHashCode(TransitionOperation obj)
        {
            int t = obj.GetType().GetHashCode();
            string token = obj.Token;
            if (token != null)
                t ^= token.GetHashCode();
            return t;
        }
    }
}
